import Vue from 'vue'
import VueRouter from 'vue-router'
import AdminMain from '../views/adminMain/AdminMain'
import axios from '../http/apis/apis.js'
import AdminSelf from '../components/admin/AdminSelf'
import AdminCreate from '../components/admin/AdminCreate'
import AdminList from '../components/admin/AdminList'
import AdminLog from '../components/admin/AdminLog'
import AdminsLogin from '../views/adminMain/AdminLogin'

Vue.use(VueRouter)

const routes = [{
            path: "/adminslogin",
            name: "adminslogin",
            component: AdminsLogin
        }, { // 当用户进入localhost:8080的时候
            path: '/',
            // 重定向
            redirect: '/lessorsLogin'
        }, {
            path: '/system',
            name: 'System',
            component: () =>
                import ('../views/system/System.vue'),
            // 导航守卫
            // 当直接进入首页的时候需要判断是否登录，不用携带数据，包装好的axios会自动携带数据
            beforeEnter: async(to, from, next) => {
                // console.log(1111111)
                const data = await axios.lessors.isLogin()
                    // console.log(data)
                if (data.status) {
                    next()
                } else {
                    console.log('未登陆')
                    next('/lessorsLogin')
                }
            },
            children: [{
                    path: 'lookOrders',
                    props: true,
                    component: () =>
                        import ('../components/orders/LookOrders.vue'),
                    meta: {
                        //设置是否需要缓存  false不需要缓存，即每次都要重新渲染
                        keepAlive: false
                    }
                },
                {
                    path: 'lessorsList',
                    props: true,
                    component: () =>
                        import ('../components/lessors/LessorsList.vue'),
                    meta: {
                        //设置是否需要缓存  false不需要缓存，即每次都要重新渲染
                        keepAlive: false
                    }
                },
                {
                    path: 'parkingsList',
                    props: true,
                    component: () =>
                        import ('../components/parkings/ParkingsList.vue'),
                    meta: {
                        //设置是否需要缓存  false不需要缓存，即每次都要重新渲染
                        keepAlive: false
                    }
                }, {
                    path: 'addParkings',
                    props: true,
                    component: () =>
                        import ('../components/parkings/AddParkings.vue'),
                    meta: {
                        //设置是否需要缓存  false不需要缓存，即每次都要重新渲染
                        keepAlive: false
                    }
                }, {
                    path: 'reviseParkings/:id',
                    props: true,
                    component: () =>
                        import ('../components/parkings/ReviseParkings.vue'),
                    meta: {
                        //设置是否需要缓存  false不需要缓存，即每次都要重新渲染
                        keepAlive: false
                    }
                }, {
                    path: 'groundingParkings',
                    props: true,
                    component: () =>
                        import ('../components/parkings/GroundingParkings.vue'),
                    meta: {
                        //设置是否需要缓存  false不需要缓存，即每次都要重新渲染
                        keepAlive: false
                    }
                }
            ]
        },
        {
            path: '/lessorsLogin',
            name: 'LessorsLogin',
            component: () =>
                import ('../views/LessorsLogin/LessorsLogin.vue')
        },
        {
            path: '/lessorsRegister',
            name: 'LessorsRegister',
            component: () =>
                import ('../views/LessorsRegister/LessorsRegister.vue')
        },
        {
            path: '/admins',
            name: 'admin',
            component: AdminMain,
            children: [{
                    path: 'lessors',
                    component: () =>
                        import ('../components/admin/LessorsList.vue'),
                },
                {
                    path: 'tenants',
                    component: () =>
                        import ('../components/admin/TenantsList.vue')
                },
                {
                    path: 'parkings',
                    component: () =>
                        import ('../components/admin/ParkingsList.vue')
                },
                {
                    path: 'orders',
                    component: () =>
                        import ('../components/admin/OrdersList.vue')
                }, {
                    path: '/admins/adminself',
                    component: AdminSelf
                },
                {
                    path: '/admins/addadmin',
                    component: AdminCreate
                },
                {
                    path: '/admins/adminlist',
                    component: AdminList
                },
                {
                    path: '/admins/adminupdate/:id',
                    component: AdminCreate,
                    props: true
                },
                {
                    path: '/admins/adminlog',
                    component: AdminLog
                },
            ],
        }
    ]
    // {
    /*
        path: '/admins',
        name: 'admins',
        component: AdminMain,
        children: [{
                path: 'lessors',
                component: () =>
                    import ('../components/admin/LessorsList.vue'),
            },
            {
                path: 'tenants',
                component: () =>
                    import ('../components/admin/TenantsList.vue')
            },
            {
                path: 'parkings',
                component: () =>
                    import ('../components/admin/ParkingsList.vue')
            },
            {
                path: '/admins',
                name: 'admin',
                component: AdminMain,
                children: [{
                        path: 'lessors',
                        component: () =>
                            import ('../components/admin/LessorsList.vue'),
                    },
                    {
                        path: 'tenants',
                        component: () =>
                            import ('../components/admin/TenantsList.vue')
                    },
                    {
                        path: 'parkings',
                        component: () =>
                            import ('../components/admin/ParkingsList.vue')
                    },
                    {
                        path: 'orders',
                        component: () =>
                            import ('../components/admin/OrdersList.vue')
                    }, {
                        path: '/admins/adminself',
                        component: AdminSelf
                    },
                    {
                        path: '/admins/addadmin',
                        component: AdminCreate
                    },
                    {
                        path: '/admins/adminlist',
                        component: AdminList
                    },
                    {
                        path: '/admins/adminupdate/:id',
                        component: AdminCreate,
                        props: true
                    },
                    {
                        path: '/admins/adminlog',
                        component: AdminLog
                    },
                ],
            }
        ]
        // {
        /*
            path: '/',
            // 重定向
            redirect: '/system'
        }, {
            path: '/system',
            name: 'System',
            component: () =>
                import ('../views/system/System.vue'),
            children: [{
                path: 'StudentsList/',
                props: true,
                // component: () => import('../comp         onents/lessors'),
                meta: {
                    keepAlive: false
                }
            }]
        }, {
            path: '/admins',
            name: 'admins',
            component: AdminMain,
            children: [
                {
                    path: 'lessors',
                    component: () =>
                        import ('../components/admin/LessorsList.vue'),
                },
                {
                    path: 'tenants',
                    component: () =>
                        import ('../components/admin/TenantsList.vue')
                },
                {
                    path: 'parkings',
                    component: () =>
                        import ('../components/admin/ParkingsList.vue')
                },
                {
                    path: 'orders',
                    component: () =>
                        import ('../components/admin/OrdersList.vue')
                },
                }
            ]
        }
            path: 'parkings',
            component: () =>
                import('../components/admin/ParkingsList.vue')
        },
                path: 'orders',
                component: () =>
                    import ('../components/admin/OrdersList.vue')
            },
        ]
    }
        path: 'parkings',
        component: () =>
            import('../components/admin/ParkingsList.vue')
    },
    ]
    }
    */
    // ]

const router = new VueRouter({
    routes
})

export default router